﻿'------------------------------
' Hien thi 5 tin moi nhat
'------------------------------
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports System.IO

Namespace NVPortal.Modules.NVNews
    Public MustInherit Class Lastest
        Inherits Entities.Modules.PortalModuleBase
#Region "Event Handlers"

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Not IsPostBack Then
                    Dim ctlNews As New NV_NewsController
                    Dim arrNews As ArrayList
                    
                    arrNews = ctlNews.LastestNews()
                    Me.drgOtherNews.DataSource = arrNews
                    Me.drgOtherNews.DataBind()
                End If
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub
        Public Function GetUser(ByVal userid As Integer) As String
            If userid = -1 Then
                GetUser = "Độc giả"
            Else
                Return UserController.GetUser(PortalId, userid, True).Username
            End If
        End Function
        Public Function CatName(ByVal catid As Integer) As String
            Dim ctlCat As New NV_NewsCategoriesController
            Dim objCat As NV_NewsCategoriesInfo
            objCat = ctlCat.GetByID(catid)
            Return objCat.CategoryName
        End Function
        Public Shared Function ToRelativeDate(ByVal dateTime__1 As DateTime) As String
            Dim timeSpan__2 = Date.Now - dateTime__1

            If timeSpan__2 <= TimeSpan.FromSeconds(60) Then
                Return String.Format("{0} giây trước", timeSpan__2.Seconds)
            End If

            If timeSpan__2 <= TimeSpan.FromMinutes(60) Then
                Return If(timeSpan__2.Minutes > 1, [String].Format("{0} phút trước", timeSpan__2.Minutes), "phút trước")
            End If

            If timeSpan__2 <= TimeSpan.FromHours(24) Then
                Return If(timeSpan__2.Hours > 1, [String].Format("{0} giờ trước", timeSpan__2.Hours), "giờ trước")
            End If

            If timeSpan__2 <= TimeSpan.FromDays(30) Then
                Return If(timeSpan__2.Days > 1, [String].Format("{0} ngày trước", CInt(timeSpan__2.Days)).ToLower, "hôm qua")
            End If

            If timeSpan__2 <= TimeSpan.FromDays(365) Then
                Return If(timeSpan__2.Days > 30, [String].Format("{0} tháng trước", CInt(timeSpan__2.Days / 30)).Trim, "about a month ago")
            End If

            Return If(timeSpan__2.Days > 365, [String].Format("{0} năm trước", timeSpan__2.Days / 365), "about a year ago")
        End Function
        Public Function Timeago(ByVal id As Integer) As String
            Dim ctlNews As New NV_NewsController
            Dim objNews As NV_NewsInfo
            objNews = ctlNews.GetByID(id)
            Return ToRelativeDate(objNews.Createdate)

        End Function
        Public Function FormatURL(ByVal sitem As String, ByVal strID As String, ByVal strLink As String) As String
            Dim i As Integer
            If IsNumeric(Settings("NVNewsDisplayPageSetting")) Then
                i = Settings("NVNewsDisplayPageSetting")
                Return "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm"
            Else
                Return "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm"
            End If
        End Function
        Public Function FormatURLcat(ByVal sitem As String, ByVal strID As String, ByVal strLink As String) As String
            Dim i As Integer
            If IsNumeric(Settings("NVNewsDisplayPageSetting")) Then
                i = Settings("NVNewsDisplayPageSetting")
                Return "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm"
            Else
                Return "/" & sitem & "/" & strID & "/" & ReplaceChuoi(strLink) & ".htm"
            End If
        End Function
        Public Function ReplaceChuoi(ByVal chuoi As String) As String
            Dim convert As String = Global.ReplaceChuoi.bodau(chuoi).Replace(" ", "-")
            Return convert
        End Function
        Public Function ImageHeight() As String
            Return IIf(Settings("NVNewsImageValueSetting") <> "", Split(Settings("NVNewsImageValueSetting"))(1), 60)
        End Function
        
#End Region
        
       
    End Class

End Namespace


